package form;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import com.sun.lwuit.Image;
import java.io.IOException;
import helper.Utilities;
import java.util.Timer;
import java.util.TimerTask;

import midlet.MainMidlet;
import model.ItemMenu;

/**
 *
 * @author Hallucinogen, LegACy
 */
public class SplashScreenForm extends ParentForm {

    public SplashScreenForm(MainMidlet midlet, ParentForm parent) {
        super(midlet, parent, null);

        Image bg = null;
        try {
            bg = Image.createImage(ParentForm.SPLASH_IMAGE);

        } catch (IOException ex) {
            System.out.println("Splash image not found <" + ParentForm.SPLASH_IMAGE + ">");
        }

        this.getStyle().setBgImage(bg);

        //Download stuff here instead of using timer
        timer.schedule(new CountDown(), 1000);
    }

    private void dismiss() {
        //Load item file
        String[] array = null;
        try {
            array = Utilities.split(Utilities.getInstance().getMenuByParentId(Utilities.PARENT_MENU), "####");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        System.out.println("jumlah array: " + array.length);

        ItemMenu[] ItemList = new ItemMenu[array.length + 1];
        for (int i = 0; i < array.length - 1; i++) {
            String[] data = Utilities.split((String) array[i], "|");

            ItemList[i] = new ItemMenu(Integer.parseInt(data[0]), data[1], data[2], Integer.parseInt(data[3]));
            System.out.println("item At[" + i + "] =" + array[i]);

        }

        //add Staict Menu
        ItemList[array.length - 1] = new ItemMenu("TNC", "text", 0);
        ItemList[array.length] = new ItemMenu("Exit", "exit", 0);

        //Create main form
        new MainFormUi(this.midlet, null, ItemList, null).show();
        this.disposeForm();
    }

    private class CountDown extends TimerTask {

        public void run() {
            dismiss();
        }
    }
    private Timer timer = new Timer();
}
